package cn.zrj.resource.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

/**
 * @author zhaorujie
 * @version v1.0
 * @date 2023/5/22
 **/
@EnableWebSecurity
@Configuration(proxyBeanMethods = false)
public class ResourceServerConfig {

    // @formatter:off
    @Bean
    SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                .securityMatcher("/messages/**")
                .securityMatcher("/test/**")
                .authorizeHttpRequests(request ->
                        request.requestMatchers("/messages/**").hasAuthority("SCOPE_message.read")
                                .requestMatchers("/test/**").authenticated()
                )


        ;
        return http.build();
    }
    // @formatter:on

}
